Skip to content

Reset the cache when the partial file is deleted mid-download - #23

Merged
Colton127 merged 1 commit into
mainfrom
claude/partial-deleted-reset
Nov 9, 2026
Merged

Colton127 merged 1 commit into
mainfrom
claude/partial-deleted-reset

Conversation

@Colton127

Copy link
Copy Markdown
Owner

Bug

When the partial cache file is deleted while its download runs (Android's cache management clearing the app cache, say), the downloader keeps writing into the deleted inode. Every ranged request for bytes the download already held then opens the missing path and fails with PathNotFoundException, until the download ends. For a streamed track this is a silent stall that can last minutes.

Fix

In HttpCacheStream.request, if a downloader that has flushed bytes (filePosition > 0) is still running and files.activeCacheFile() no longer exists, the stream resets the cache (_resetCache with InvalidCacheSizeException(sourceUrl, -1, sourceLength), so the deletion is reported on cacheStateStream) and queues the request instead of handing it to the old downloader. The download starts again and the request is served once its range is downloaded.

Tests

  • New test/e2e/partial_deleted_test.dart: holds the origin at half the body, deletes the partial file, then reads a range it had already downloaded. Fails without the fix (PathNotFoundException), passes with it; the full download then completes with the right hash.
  • flutter test: all 148 pass. dart analyze lib test: no issues (flutter analyze's issues are the existing ones in benchmarker/).
  • CHANGELOG: entry under ## Unreleased.

@Colton127
Colton127 merged commit 94a8f09 into main Nov 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant